﻿using FirstApiTest.Controllers.Domian.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FirstApiTest.Controllers.Domian
{
    public class DbInitializeHelper
    {
        public static void Initializer()
        {
            using (var db = new AdminContext4000())
            {
                db.Database.EnsureCreated();
                if (!db.Brands.Any())
                {
                    var brand = new Brand
                    {
                        BrandName = "华为",
                        Description = "中华有为，黑的居多"
                    };
                    db.Brands.Add(brand);
                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName="华为P30Pro，非常Pro",
                        ShortDesc="简介自己去网上找",
                        FullDesc="详细介绍我不知道",
                        BrandId = brand.Id
                    },new Product
                    {
                        ProductName="华为P20Pro，非常垃圾",
                        ShortDesc="简介自己去网上找",
                        FullDesc="详细介绍我不知道",
                        BrandId = brand.Id
                    }
                    });
                    db.SaveChanges();
                }
            }
        }
    }
}
